<%--
  Created by IntelliJ IDEA.
  User: 韩金龙
  Date: 2021/11/22
  Time: 17:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-1.8.2.min.js"></script>
    <script src="js/fileupload.js"></script>
    <link rel="stylesheet" href="css/css.css">
    <link rel="stylesheet" href="css/img.css">
</head>
<body>
<form>
    文章标题:<input type="text" name="title"><br>
    文章图片:<div class="photoUpLoad" >
    <input type="file"   class="photo" name="photo" accept="image/*"><span class="cross">+</span>
    <img src="" alt="" class="photoEcho"></div>
    <br>
    文章内容:<textarea name="content"></textarea><br>
    文章标签:<div id="tid"></div>
</form>
<button onclick="add()">添加</button>
</body>
<script>
    $(function () {
        $.ajax({
            url:"tagList.do",
            type:"post",
            dataType:"json",
            success:function(obj) {
                console.log(obj)
                for (let i in obj) {
                    $("#tid").append('<input type=checkbox name=tagids value="'+obj[i].id+'">'+obj[i].name+'')
                }
            }
        })
    })
    function add() {
        var formData = new FormData($("form")[0]);
        $.ajax({
            url:"add.do",
            type:"post",
            data:formData,
            dataType:"json",
            success:function(obj) {
                console.log(obj)
                if (obj>0){
                    alert("添加成功!!")
                    location="list.do"
                }
            },
            processData:false,
            contentType:false,
        })
    }
</script>
</html>
